﻿@{
    var action = ViewContext.RouteData.Values["Action"] as string;
    Pager pager = ViewBag.Pager;
}
<div class="text-center">
    <ul class="pagination">
        @if (pager.HasPreviousPage)
        {
            <li>@Html.ActionLink("<<", action, Html.OverRoute(new { page = pager.FirstPageIndex }))</li>
            <li>@Html.ActionLink("<", action, Html.OverRoute(new { page = pager.PreviousPageIndex }))</li>
        }

        @foreach (int page in pager)
        {
            if (page == pager.CurrentPageIndex)
            {
                <li class="active"><span>@page</span></li>
            }
            else
            {
                <li>@Html.ActionLink(page.ToString(), action, Html.OverRoute(new { page }))</li>
            }
        }

        @if (pager.HasNextPage)
        {
            <li>@Html.ActionLink(">", action, Html.OverRoute(new { page = pager.NextPageIndex }))</li>
            <li>@Html.ActionLink(">>", action, Html.OverRoute(new { page = pager.LastPageIndex }))</li>
        }
    </ul>
</div>
